import * as validator from './validator';
import * as rule from './rule';

export default {
  getValidator(validatorName, params) {
    switch (validatorName) {
      case 'positiveInteger':
        return validator.createPositiveInteger();
      case 'nonNegativeInteger':
        return validator.createNonNegativeInteger();
      case 'mobile':
        return validator.createMobile(params);
      case 'email':
        return validator.createEmail(params);
      case 'password':
        return validator.createPassword(params);
      case 'cardNumber':
        return validator.createCardNumber(params);
      case 'inRangeFloat':
        return validator.createInRangeFloat(params);
      case 'uri':
        return validator.createUri(params);
      case 'nonNegativeNumber':
        return validator.createNonNegativeNumber(params);
      case 'createpointsLimit':
        return validator.createpointsLimit(params);
      case 'createNoStartWithZero':
        return validator.createNoStartWithZero(params);
      case 'proportion':
        return validator.createProportion(params);
      default:
        throw new Error(`没有找到validator${validatorName}`);
    }
  },
  getRule(ruleName) {
    switch (ruleName) {
      case 'username':
        return rule.createUsername();
      case 'adminUsername':
        return rule.createAdminUsername();
      case 'password':
        return rule.createPassword();
      case 'passwordMixType':
        return rule.createPasswordMixType();
      case 'uri':
        return rule.createUri();
      case 'activeUri':
        return rule.createActiveUri();
      case 'cardNumber':
        return rule.createCardNumber();
      case 'rate':
        return rule.createRate();
      case 'percent':
        return rule.createPercent();
      case 'percent1000':
        return rule.createPercent1000();
      case 'times':
        return rule.createTimes();
      case 'money':
        return rule.createMoney();
      case 'floatMoney':
        return rule.createFloatMoney();
      case 'moneyType':
        return rule.createMoneyType();
      case 'multiple':
        return rule.createMultipleType();
      default:
        throw new Error(`没有找到rule${ruleName}`);
    }
  },
};
